#include <vector>
#include <fstream>
#include <iostream>

using namespace std;

int speeding() {
  ifstream ifs("Speeding.in");

  int n = 0, m = 0;

  ifs >> n >> m;

  // 读入高速公路的限速信息
  vector<int> limits(100, 0);

  int start = 0;
  for (int i = 0; i < n; ++i) {
    int len = 0, speed = 0;
    ifs >> len >> speed;

    for (int j = start; j < start + len; ++j) {
      limits[j] = speed;
    }

    start += len;
  }

  start = 0;
  vector<int> bessie(100, 0);

  for (int i = 0; i < m; ++i) {
    int len = 0, speed = 0;
    ifs >> len >> speed;

    for (int j = start; j < start + len; ++j) {
      bessie[j] = speed;
    }

    start += len;
  }

  int maxSpeed = 0;

  for (int i = 0; i < 100; ++i) {
    maxSpeed = max(maxSpeed, bessie[i] - limits[i]);
  }

  // maxSpeed
  ofstream ofs("Speeding.out");
  ofs << maxSpeed;

  return maxSpeed;
}

int main(int argc, char const *argv[])
{
  /* code */
  speeding();
  return 0;
}
